package com.tool.imp;

import java.util.Random;

import com.kingdee.bos.util.backport.concurrent.atomic.AtomicInteger;

/**
 * 数据库ID生成帮助类
 * 
 * @author Evan.Hu
 * 
 */
public class KeyGenerator {
	private static AtomicInteger var = new AtomicInteger(1);

	private static final String[] keys = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };

	/**
	 * 生成20为Key
	 * 
	 * @return
	 */
	public static String randomKey20() {
		if (var.get() > 9999) {
			// 大于9999后，重新循环
			var.set(1);
		}
		final int seq = var.getAndIncrement();
		// 当前毫秒 + 4位时序数，最后一位随机数
		return Long.toString(System.currentTimeMillis()) + keys[seq / 1000] + keys[seq / 100] + keys[seq / 10] + keys[seq % 10]
				+ keys[new Random().nextInt(10)];
	}
}
